package com.xingkeduo.business.user.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.xingkeduo.business.transformation.json.BaseDTOJTO;
import com.xingkeduo.business.transformation.json.ConsumerStyleJTO;
import com.xingkeduo.business.user.domain.ConsumerDomain;
import com.xingkeduo.pojo.phppojo.ResponseResult;
import com.xingkeduo.pojo.query.ConsumerStyleQO;
import com.xingkeduo.pojo.table.ConsumerStyleTO;
import com.xingkeduo.util.pojo.base.BaseController;
import com.xingkeduo.util.pojo.enums.YesNoEnum;
import com.xingkeduo.util.pojo.exception.DataException;

/**
 * @Description:
 * @Author:pantong
 * @Date 2019/4/29 10:00
 **/
@RestController
@RequestMapping("/consumerStyle")
public class ConsumerStyleController extends BaseController {

    @Autowired
    private ConsumerDomain consumerDomain;
    
    /**
     * 查询定位风格
     * @param f_user_id
     * @param time
     * @param token
     * @param mobile_type
     * @author : pantong
     * @return
     * @throws Throwable
     */
    @GetMapping("/update_style")
    public Object update_style(long f_user_id, String time, String token, String mobile_type) throws Throwable{
    	try {
    		ConsumerStyleQO consumerStyleQO = new ConsumerStyleQO();
    		consumerStyleQO.setConsumerId(f_user_id);
    		consumerStyleQO.setType(1);
    		consumerStyleQO.setIsDelete(YesNoEnum.NO);
    		List<ConsumerStyleTO> consumerStylsList = consumerDomain.getConsumerStylsList(consumerStyleQO);
    		return BaseDTOJTO.toSuccessJson(ConsumerStyleJTO.toJson(consumerStylsList));
    	}catch (DataException e) {
    		dealException(e);
    		return BaseDTOJTO.toErrorJson(e.getMessage());
    	}catch (Exception e) {
    		dealException(e);
    		return BaseDTOJTO.toErrorJson("操作失败，请稍后重试！");
		}
    }
    

    /**
     * 修改用户风格定位
     * @param f_user_id
     * @param time
     * @param token
     * @param choose_style_list_ids
     * @param mobile_type
     * @return
     * @throws Throwable
     */
    @GetMapping("/ajax_update_style")
    public String ajax_update_care(long f_user_id, String time, String token, String choose_style_list_ids, String mobile_type) throws Throwable {
        try {
            consumerDomain.updateConsumerStyle(f_user_id, time, token, choose_style_list_ids, mobile_type);
            return new ResponseResult().success();
        }catch (DataException e) {
        	dealException(e);
			return new ResponseResult().exceptionForTransfer(null, e.getMessage());
    	}catch (Exception e) {
    		dealException(e);
    		return new ResponseResult().exceptionForTransfer(null, "修改失败，请稍后重试！");
		}
    }
    
}
